package com.heima.test5;

public class Demo01 {
    public static void main(String[] args) {
        Object objA = new Object();
        Object objB = new Object();

        new Thread(() -> {
            while (true) {
                synchronized (objA) {
                    //线程一
                    System.out.println("小康进入a");
                    synchronized (objB) {
                        System.out.println("小康进入b");
                        System.out.println("小康同学正在走路");
                    }
                }
            }
        }).start();

        new Thread(() -> {
            while (true) {
                synchronized (objB) {
                    //线程二
                    System.out.println("小薇进入B");
                    synchronized (objA) {
                        System.out.println("小薇进入A");
                        System.out.println("小薇同学正在走路");
                    }
                }
            }
        }).start();
    }
}
